package Controller;

import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import Model.Person;

/**
 * Listener de la liste du JTable des contacts
 * @author antoinerichard
 *
 */
public class SharedListeSelectionHandler implements ListSelectionListener {
	
	AdressBookController controller;
	
	public SharedListeSelectionHandler(AdressBookController a)
	{
		this.controller=a;
	}
	
    public void valueChanged(ListSelectionEvent e) {
       
    	
    	ListSelectionModel lsm = (ListSelectionModel)e.getSource();
    	if(lsm.getMinSelectionIndex()!=-1)
    	{
        
        String tempDate=(String) controller.Cadre.getTable().getValueAt(lsm.getMinSelectionIndex(), 3);
        Person chosenPerson = controller.Livre.findPersonByData(tempDate);
        
        
        
        controller.Cadre.switchToProfileView();
        controller.Cadre.setProfile(chosenPerson);
    	}
        
       
    }

	
}